import {
  reduceArr
} from '@/utils/categoryOrTags';

// 更新栏目标签+分类标签
export function updateTags(arr, options) {
  // 分类
  if (arr.categorySelect && arr.categorySelect.length > 0) {
    arr.categoryTag = [];
    options.category = reduceArr(options.category);
    // console.log('分类:', options.category, arr.categorySelect);
    arr.categorySelect.map(item => {
      var itemStr = typeof item !== 'string' ? item[item.length - 1] : item;
      var items = options.category.filter(
        data => itemStr === data.tagsId
      );
      // console.log('分类items:', items);
      if (items[0]) {
        arr.categoryTag.push({
          id: items[0].tagsId,
          name: items[0].tagsName
        });
      }
    });
  } else {
    arr.categoryTag = [];
  }

  console.log('arr.contentSelect:', arr.contentSelect);
  console.log('options:', options);
  // 标签
  if (arr.contentSelect && arr.contentSelect.length > 0) {
    arr.columnTag = [];
    options.content = reduceArr(options.content);
    console.log('标签:', options.content);
    arr.contentSelect.map(item => {
      var itemStr = typeof item !== 'string' ? item[item.length - 1] : item;
      var items = options.content.filter(
        data => itemStr === data.tagsId
      );
      if (items[0]) {
        arr.columnTag.push({
          id: items[0].tagsId,
          name: items[0].tagsName
        });
      }
    });
  } else {
    arr.columnTag = [];
  }

  return arr;
}
